function [race]= cal_entropy(cmatrix, group)

%%%%%%%%%%%%%%%Textural feature extraction%%%%%%%%%%%%%%%%%%%%%%
% B=cmatrix(1:128,129:256);
% D=cmatrix(129:256,1:128);

cmatrixsum=sum(sum(cmatrix));
% Bsum=sum(sum(B));
% Dsum=sum(sum(B));


if cmatrixsum~=0
    cmatrix=cmatrix./cmatrixsum;
end


% if Bsum~=0
%     B=B./Bsum;
% end
% if Dsum~=0
%     D=D./Dsum;
% end

% b_entropy=0;
% b_moment=0;
% d_entropy=0;
% d_moment=0;

% sizeb=size(B);
% sized=size(D);
% 
% for i=1:sizeb(1)
%     for j=1:sizeb(2)
%         b_entropy = b_entropy + (B(i,j)* exp(1-B(i,j)));
%         b_moment = b_moment + B(i,j)/(1+(i-j)*(i-j)); 
%     end
% end
% 
% for i=1:sized(1)
%     for j=1:sized(2)
%         d_entropy = d_entropy + (D(i,j)* exp(1-D(i,j)));
%         d_moment = d_moment + D(i,j)/(1+(i-j)*(i-j));
%     end
% end

%____________CONTRAST____________
pxplusy=zeros(512);
pxminusy=zeros(256);
% 
for i=1:256
   for j=1:256
       pxplusy(i+j)=pxplusy(i+j)+cmatrix(i,j);
%         pxminusy(abs(i-j)+1)=pxminusy(abs(i-j)+1)+cmatrix(i,j);
   end
 end
% 
% contrast=0;
% for n=1:256
%     contrast = contrast+ (n-1)*(n-1)*pxminusy(n);
% end

sizem=size(cmatrix);
entropy=0;
moment=0;
variance=0;
sumaverage=0;

meanmatrix=mean(mean(cmatrix));

for i=1:sizem(1)
    for j=1:sizem(2)
        entropy= entropy + (cmatrix(i,j)* exp(1-cmatrix(i,j)));
%         moment = moment + cmatrix(i,j)/(1+(i-j)*(i-j));
        variance=variance+ (i-meanmatrix)*(i-meanmatrix)*cmatrix(i,j);
    end
end
variance=uint16(variance);

for i=2:512
    sumaverage=sumaverage+(i*pxplusy(i));
end



% entropy=(b_entropy + d_entropy)/2;
% moment=(b_moment + d_moment)/2;
asm=0;
for i=1:256
    for j=1:256
       asm=asm+(cmatrix(i,j)*cmatrix(i,j));
    end
end
asm
        
entropy
% moment
variance
sumaverage

%contrast

%%%%%%%%%%%%%%%Comparison and Race Calculation%%%%%%%%%%%%%%%%%
VALUES= [entropy variance sumaverage];
CA_VALUES= [1.6 5000 70];
race='';
count=0;
if(strcmp(group,'CA'))
    if (sum(VALUES > CA_VALUES) == 3)
        race='Caucasian';
    else
        race='Asian';
    end
else
    if(1.5 <=entropy) &&( entropy <=2)
        count=count+1;
    end
    if((60 <= sumaverage) && (sumaverage <= 130) || (sumaverage <= 30))
        count=count+1;
    end
    if(asm > 0.5)
        count=count+1;
    end
    if (count >= 2)
        race= 'Black';
    else
        race= 'Asian';
    end
end
race
    